/*
 * Copyright (C), 2002-2015, 你的兔宝宝电子商务有限公司
 * FileName: StaticsClassFactoryBean.java
 * Author:   你的兔宝宝
 * Date:     2015-3-17 上午10:21:40
 * Description: 构造静态类freemarker对象//模块目的、功能描述      
 * History: //修改记录
 * <author>      <time>      <version>    <desc>
 * 修改人姓名             修改时间            版本号                  描述
 */
package com.baby.demo.utils.factory;

import org.springframework.beans.factory.config.AbstractFactoryBean;

import freemarker.ext.beans.BeansWrapper;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModelException;

/**
 * 〈构造静态类freemarker对象〉<br> 
 * 〈功能详细描述〉
 *
 * @author 你的兔宝宝
 * @see [相关类/方法]（可选）
 * @since [产品/模块版本] （可选）
 */
public class StaticsClassFactoryBean extends AbstractFactoryBean<TemplateHashModel> {

    /**
     * 静态类名
     */
    private String staticsClassName;
    
    
    @Override
    public Class<TemplateHashModel> getObjectType() {
        return TemplateHashModel.class;
    }

    @Override
    public boolean isSingleton() {
        return false;
    }

    @Override
    protected TemplateHashModel createInstance() throws Exception {
        BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        return (TemplateHashModel) staticModels.get(staticsClassName);
    }
    
    public static TemplateHashModel factory(String staticsClassName) throws TemplateModelException{
        BeansWrapper wrapper = BeansWrapper.getDefaultInstance();
        TemplateHashModel staticModels = wrapper.getStaticModels();
        return (TemplateHashModel) staticModels.get(staticsClassName);
    }
    
    /**
     * @return the staticsClassName
     */
    public String getStaticsClassName() {
        return staticsClassName;
    }

    /**
     * @param staticsClassName the staticsClassName to set
     */
    public void setStaticsClassName(String staticsClassName) {
        this.staticsClassName = staticsClassName;
    }

    
    
}
